package wci.intermediate.symtabimpl;

import java.util.ArrayList;

import wci.intermediate.*;

/**
 * <h1>SymTabStack</h1>
 *
 * <p>符号表栈的实现</p>
 *
 * <p>Copyright (c) 2009 by Ronald Mak</p>
 * <p>For instructional purposes only.  No warranties.</p>
 */
public class SymTabStackImpl
    extends ArrayList<SymTab>
    implements SymTabStack
{
	private static final long serialVersionUID = -6353713712087666465L;
	private int currentNestingLevel;  // 当前嵌套，默认为全局的0
    public SymTabStackImpl()
    {
        this.currentNestingLevel = 0;
        add(SymTabFactory.createSymTab(currentNestingLevel));
    }
    public int getCurrentNestingLevel()
    {
        return currentNestingLevel;
    }

    public SymTab getLocalSymTab()
    {
        return get(currentNestingLevel);
    }
    public SymTabEntry enterLocal(String name)
    {
        return get(currentNestingLevel).enter(name);
    }
    public SymTabEntry lookupLocal(String name)
    {
        return get(currentNestingLevel).lookup(name);
    }
    public SymTabEntry lookup(String name)
    {
    	//目前只有一个符号表在栈中，所以全局即局部
        return lookupLocal(name);
    }
}
